package com.eling.elcms.travel.service.impl;

import com.eling.elcms.basedoc.model.view.RoomStatisticsView;
import com.eling.elcms.core.service.impl.GenericManagerImpl;
import com.eling.elcms.core.util.PropertyUtils;
import com.eling.elcms.travel.dao.IShiftChangeDao;
import com.eling.elcms.travel.model.CheckInCar;
import com.eling.elcms.travel.model.CheckInMeeting;
import com.eling.elcms.travel.model.ShiftChange;
import com.eling.elcms.travel.model.view.ChargeTotalView;
import com.eling.elcms.travel.model.view.CheckInCountView;
import com.eling.elcms.travel.model.view.MemberCountView;
import com.eling.elcms.travel.service.ICheckInCarManager;
import com.eling.elcms.travel.service.ICheckInMeetingManager;
import com.eling.elcms.travel.service.IShiftChangeManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Service
public class ShiftChangeManagerImpl extends GenericManagerImpl<ShiftChange, Long> implements IShiftChangeManager{

	IShiftChangeDao shiftChangeDao;
	
	@Autowired
	private ICheckInMeetingManager CheckInMeetingM;
	@Autowired
	private ICheckInCarManager checkInCarM;

	@Autowired
	public void setShiftChangeDao(IShiftChangeDao shiftChangeDao) {
		this.dao = shiftChangeDao;
		this.shiftChangeDao = shiftChangeDao;
	}

	@Override
	public List<CheckInCountView> queryCheckInCount(Date shiftChangeDate) {
		return shiftChangeDao.queryCheckInCount(shiftChangeDate);
	}

	@Override
	public List<CheckInMeeting> queryMeeting(Date createDate,Date createEndDate) {
		
		CheckInMeeting checkInMeeting = new CheckInMeeting();
		PropertyUtils.setProperty(checkInMeeting, "meetingDate", createDate);
		PropertyUtils.setProperty(checkInMeeting, "meetingDateEnd", createEndDate);
		List<CheckInMeeting> checkInMeetings = CheckInMeetingM.query(checkInMeeting);
		return checkInMeetings;
	}

	@Override
	public List<CheckInCar> queryCar(Date createDate,Date createEndDate) {
		CheckInCar checkInCar = new CheckInCar();
		PropertyUtils.setProperty(checkInCar, "carDate", createDate);
		PropertyUtils.setProperty(checkInCar, "carDateEnd", createEndDate);
		List<CheckInCar> checkInCars = checkInCarM.query(checkInCar);
		return checkInCars;
	}

	@Override
	public List<RoomStatisticsView> queryStatistics(Date shiftChangeDate) {
		Calendar day = Calendar.getInstance();
		day.setTime(shiftChangeDate);
		day.set(Calendar.HOUR_OF_DAY, 0);
		day.set(Calendar.MINUTE, 0);
		day.set(Calendar.SECOND, 0);
		day.set(Calendar.MILLISECOND, 0);
		Date startDate = day.getTime();
		day.setTime(shiftChangeDate);
		day.set(Calendar.HOUR_OF_DAY, 23);
		day.set(Calendar.MINUTE, 59);
		day.set(Calendar.SECOND, 59);
		day.set(Calendar.MILLISECOND, 999);
		Date endDate = day.getTime();
		return shiftChangeDao.queryStatistics(startDate,endDate);
		
	}

	@Override
	public List<MemberCountView> queryMember(Date shiftChangeDate) {
		
		return shiftChangeDao.queryMember(shiftChangeDate);
	}

	@Override
	public List<ChargeTotalView> queryCharge(Date shiftChangeDate) {
		Calendar day = Calendar.getInstance();
		day.setTime(shiftChangeDate);
		day.set(Calendar.HOUR_OF_DAY, 0);
		day.set(Calendar.MINUTE, 0);
		day.set(Calendar.SECOND, 0);
		day.set(Calendar.MILLISECOND, 0);
		Date startDate = day.getTime();
		day.setTime(shiftChangeDate);
		day.set(Calendar.HOUR_OF_DAY, 23);
		day.set(Calendar.MINUTE, 59);
		day.set(Calendar.SECOND, 59);
		day.set(Calendar.MILLISECOND, 999);
		Date endDate = day.getTime();
		return shiftChangeDao.queryCharge(startDate,endDate);
	}
}
